package com.armrest.screen.provider

import android.media.MediaPlayer
import android.widget.ImageView
import android.widget.RelativeLayout
import com.armrest.screen.*
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class SgravityModelProvider(
    var layout: Int = R.layout.sgravity_model_home_layout, var itemViewTypes:
    Int = ItemViewType.ITEM_TYPE_GRAVITY_MODEL
) : BaseItemProvider<HomeMenuModel>() {
    override val itemViewType: Int
        get() = itemViewTypes
    override val layoutId: Int
        get() = layout

    var itemClick: ((position: Boolean) -> Unit)? = null
    private var gravityBoolean: Boolean = false

    override fun convert(helper: BaseViewHolder, item: HomeMenuModel) {
        val gravityLl = helper.getViewOrNull<RelativeLayout>(R.id.gravity_ll)
        val gravityImg = helper.getViewOrNull<ImageView>(R.id.gravity_img)
        val tpisTv = helper.getViewOrNull<ImageView>(R.id.tpis_tv)
        val openOff = helper.getViewOrNull<ImageView>(R.id.open_off)
         gravityImg?.setObjectAnimator()
         gravityLl?.let {
            gravityLl.setOnClickListener {
                it.setMediaPlayer()
                it.setBackgroundResource(if (gravityBoolean) R.mipmap.card_seat_on_bg else R.mipmap.card_seat_off_bg)
                gravityImg?.setImageResource(if (gravityBoolean) R.mipmap.icon_seat_on else R.mipmap.icon_seat_off)
                tpisTv?.setImageResource(if (gravityBoolean) R.mipmap.sgravity_text_image else R.mipmap.sgravity_text_image_bak)
                openOff?.setImageResource(if (gravityBoolean) R.mipmap.text_close_image else R.mipmap.text_start_on_image)
                itemClick?.invoke(gravityBoolean)
                gravityBoolean = !gravityBoolean
            }
        }
    }
}